; *******************************************************************
; Multfit efficient processing of 2D diffraction images
; Copyright (C) 2000-2014 S. Merkel, Universite Lille 1
; http://merkel.zoneo.net/Multifit/
; 
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
; 
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
;
; *******************************************************************

function fourier, X, A
;        0 - a(0)
;        1 - a(1)    -> cos(x)
;        2 - a(2)    -> sin(x)
;        3 - a(3)    -> cos(2x)
;        4 - a(4)    -> sin(2x)
; 
nel = N_ELEMENTS(A-1)/2
f = replicate(A(0), N_ELEMENTS(X))
for i=1, nel do begin
	j = 2*(i-1)+1
	k = 2*(i-1)+2
	f = f + A(j) * cos(i*x) + A(k) * sin(i*x)
endfor
return, f
end
